package com.bluedot.bank.action;

import java.util.Date;

import com.bluedot.bank.dao.role.Role;
import com.bluedot.bank.dao.role.RoleDao;
import com.bluedot.bank.dao.role.RoleDaoImpl;
import com.bluedot.bank.dao.user.User;
import com.bluedot.bank.dao.user.UserDao;
import com.bluedot.bank.dao.user.UserDaoImpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class AddUserAction extends ActionSupport {
	private User user=new User();
	private long roleId;

	/**
	 * @return the roleId
	 */
	public long getRoleId() {
		return roleId;
	}

	/**
	 * @param roleId the roleId to set
	 */
	public void setRoleId(long roleId) {
		this.roleId = roleId;
	}

	/**
	 * @return the user
	 */
	public User getUser() {
		return user;
	}

	/**
	 * @param user the user to set
	 */
	public void setUser(User user) {
		this.user = user;
	}
	@Override
	public String execute() throws Exception {
		UserDao userDao=new UserDaoImpl();
		RoleDao roleDao=new RoleDaoImpl();
		Role role=roleDao.findById(roleId);
		user.setRole(role);
		Date t=new Date();
		user.setInit_time(t);
		user.setCheck_time(t);
		user.setCheck_user((User)ActionContext.getContext().getSession().get("user"));
		userDao.saveOrUpdate(user);
		return SUCCESS;
	}

}
